package com.ufaud.ais.sys.dao.hibernate;

import java.util.Iterator;
import java.util.Set;

import com.ufaud.ais.pub.dao.hibernate.GenericCRUDDaoHibernate;
import com.ufaud.ais.sys.dao.IDepartmentDao;
import com.ufaud.ais.sys.entity.Department;

public class DepartmentDaoHibernate extends GenericCRUDDaoHibernate<Department, Long> implements IDepartmentDao {

	public DepartmentDaoHibernate() {
		super(Department.class);
	}
	
	public void initSuperDept(Department dept) {
		getHibernateTemplate().initialize(dept.getSuperDept());
	}
	
	public void initSubDept(Department dept) {
		getHibernateTemplate().initialize(dept.getSubDeptSet());
	}

	public void recInitSubDept(Department dept) {
		initSubDept(dept);
		Set<Department> subDeptSet = dept.getSubDeptSet();
		for (Iterator<Department> iter = subDeptSet.iterator(); iter.hasNext();) {
			Department oneSubDept = iter.next();
			recInitSubDept(oneSubDept);
		}
	}

	public void initDeptManager(Department dept) {
		getHibernateTemplate().initialize(dept.getDeptManager());
	}

	public void recInitDeptManager(Department dept) {
		initDeptManager(dept);
		Set<Department> subDeptSet = dept.getSubDeptSet();
		// if(subDeptSet.size() == 0)
		// return;
		for (Iterator<Department> iter = subDeptSet.iterator(); iter.hasNext();) {
			Department oneSubDept = iter.next();
			recInitDeptManager(oneSubDept);
		}
	}

}
